﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text.RegularExpressions;

namespace Clipping.Infrastructure.Models
{
    [Serializable]
    public class News
    {
        #region 字段
        protected string _title = "";
        protected string _url = "";
        protected string _media = "";
        protected string _pubdate = "";
        protected string _author = "";
        protected string _content = "";
        protected string _tone = "";
        protected string _summary = "";
        protected string _source = "";
        protected int _words = 0;
        protected string _city = "";
        protected string _channel = "";
        protected int _ad = 0;
        protected string _id = "";
        protected int _piccount = 0;
        protected List<News> _samenews = null;
        #endregion

        #region 属性


        /// <summary>
        /// 添加相同新闻
        /// </summary>
        /// <param name="news">要添加的新闻</param>
        public void AddSameNews(News news)
        {
            if (news != null)
            {
                if (this._samenews == null)
                    this._samenews = new List<News>();
                if (this.Url != news.Url)
                    this._samenews.Add(news);
            }
        }

        /// <summary>
        /// 获取或设置新闻标题属性
        /// </summary>
        public string Title
        {
            get { return this._title; }
            set
            {
                if (!string.IsNullOrEmpty(value))
                {
                    this._title = value.Trim();
                }
                else
                {
                    this._title = "";
                }
            }
        }

        /// <summary>
        /// 获取或设置新闻页面地址属性
        /// </summary>
        public string Url
        {
            get { return this._url; }
            set
            {
                if (!string.IsNullOrEmpty(value))
                {
                    this._url = value.Trim();
                }
                else
                {
                    this._url = "";
                }
            }
        }
        static CultureInfo cnCulture = new CultureInfo("zh-CN");
        /// <summary>
        /// 获取或设置新闻日期属性
        /// </summary>
        public string PubDate
        {
            get { return this._pubdate; }
            set
            {
                if (!string.IsNullOrEmpty(value))
                {
                    DateTime dt;
                    if (DateTime.TryParse(value, out dt))
                        this._pubdate = value;
                    else if (Regex.IsMatch(value, @"\d+年\d+月\d+日"))
                    {
                        this._pubdate = value;
                    }
                    else
                        this._pubdate = string.Empty;
                }
                else
                    this._pubdate = string.Empty;
            }
        }

        /// <summary>
        /// 获取或设置新闻媒体属性
        /// </summary>
        public string Media
        {
            get { return this._media; }
            set
            {
                if (string.IsNullOrEmpty(value))
                {
                    this._media = "";
                }
                else
                {
                    this._media = value;
                }
            }
        }

        /// <summary>
        /// 获取或设置新闻摘要属性
        /// </summary>
        public string Summary
        {
            get { return this._summary; }
            set
            {
                if (string.IsNullOrEmpty(value))
                {
                    this._summary = "";
                }
                else
                {
                    this._summary = value;
                }
            }
        }

        /// <summary>
        /// 获取或设置新闻中包含的图片数量
        /// </summary>
        protected int PicCount
        {
            get { return _piccount; }
            set { _piccount = value; }
        }




        /// <summary>
        /// 获取或设置相同新闻地址属性
        /// </summary>
        public string SameNewsUrl { get; set; }

        public bool HasSameNews
        {
            get
            {
                if (string.IsNullOrEmpty(SameNewsUrl))
                    return false;
                else
                    return true;
            }
        }

        public  bool SameNewsRetrived { get; set; }

        /// <summary>
        /// 获取相同新闻
        /// </summary>
        public List<News> SameNews
        {
            get { return this._samenews; }
        }

        /// <summary>
        /// 获取或设置语气
        /// </summary>
        public string Tone
        {
            get { return _tone; }
            set { _tone = value; }
        }
        /// <summary>
        /// 获取或设置频道
        /// </summary>
        public string Channel
        {
            get { return _channel; }
            set { _channel = value; }
        }
        /// <summary>
        /// 获取或设置作者
        /// </summary>
        public string Author
        {
            get { return _author; }
            set { _author = value; }
        }
        /// <summary>
        /// 获取或设置字数
        /// </summary>
        public int Words
        {
            get { return _words; }
            set { _words = value; }
        }
        /// <summary>
        /// 获取或设置广告价值
        /// </summary>
        public int Ad
        {
            get { return _ad; }
            set { _ad = value; }
        }
        /// <summary>
        /// 获取或设置正文
        /// </summary>
        public string Content
        {
            get { return _content; }
            set { _content = value; }
        }
        /// <summary>
        /// 获取或设置图片数量
        /// </summary>
        public int PictureCount
        {
            get { return _piccount; }
            set { _piccount = value; }
        }


        /// <summary>
        /// 是否准备就绪（仅在批量上传时用到）
        /// </summary>
        public bool IsReady { get; set; }

        /// <summary>
        /// 相同新闻数量
        /// </summary>
        public int SameNewsCount { get; set; }
        #endregion
    }
}
